﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhanMemBus;

namespace Pham_mem_hoc_C.PhanMem
{
    public partial class GhiNho : Form
    {
       // ThucHanhBus ghinho = new ThucHanhBus();
        LyThuyetBUS ghinho = new LyThuyetBUS();
        public GhiNho()
        {
            InitializeComponent();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            string tenchuong = comboBox1.Text.ToString();
            string tenbv = comboBox2.Text.ToString();
            try
            {
                ghinho.GhiNho(tenchuong, tenbv, rtbGhiNho.Text.ToString());
                MessageBox.Show("Ghi nhớ thành công!!! ");
            }
            catch
            {
                MessageBox.Show("Ghi nhớ thất bại!!!");
            }
           

        }

        private void rtbGhiNho_TextChanged(object sender, EventArgs e)
        {
            btnLuu.Enabled = true;
            
            
        }
        private void LoadChuong()
        {
            
            comboBox1.DataSource = ghinho.ten_chuong();
            comboBox1.DisplayMember = "ten_kn";
          
           
        }
        private void loadbaiviet()
        {
            string str = comboBox1.Text;
            comboBox2.Text = "";
            rtbGhiNho.Text = "";
            comboBox2.DataSource = ghinho.tenBaiViet(str);
            comboBox2.DisplayMember = "ten_bhct";
        }

        private void GhiNho_Load(object sender, EventArgs e)
        {
            LoadChuong();
        }

       
        private void btnhienghinho_Click(object sender, EventArgs e)
        {
            string tenchuong = comboBox1.Text.ToString();
            string tenbv = comboBox2.Text.ToString();
            DataTable dtb = ghinho.HienGhiNho(tenchuong, tenbv);
            try
            {
                rtbGhiNho.Text = dtb.Rows[0]["ghi_nho"].ToString();
            }
            catch 
            {

                MessageBox.Show("Không có nội dung ghi nhớ");
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadbaiviet();
        }
      
    }
}
